package com.mrwang.example.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class WebClient {
	public static void main(String[] args) throws IOException {
		try {
			SocketChannel socketChannel = SocketChannel.open();
			socketChannel.connect(new InetSocketAddress("127.0.0.1", 8000));

			ByteBuffer writeBuffer = ByteBuffer.allocate(32);
			ByteBuffer readBuffer = ByteBuffer.allocate(32);

			writeBuffer.put("hello".getBytes());
			writeBuffer.flip();

			writeBuffer.rewind();
			socketChannel.write(writeBuffer);
			readBuffer.clear();
			socketChannel.read(readBuffer);
			System.out.println("web client -->"+new String(readBuffer.array()));
		} catch (IOException e) {
		}
	}
}